Skip to main content

The Conversation Namespace

The Conversation namespace includes methods that give you access to Conversation and ConversationMessage objects.

The Conversation Object

Conversation objects represent interaction pairs between Subscribers and Addresses. Each Conversation object has the following properties:

FieldDescription
idA unique identifier for the conversation.
nameThe name of the conversation.
metadataAdditional metadata associated with the conversation.
created_atThe UNIX timestamp when the conversation was created.
last_message_atThe UNIX timestamp of the last message in the conversation.

Here is an example of a Conversation object:

{
"id": "9dbe9e94-c797-461e-b5a3-af6d095deaf4",
"name": "conversation-office",
"metadata": {},
"created_at": 1708192187729,
"last_message_at": 1708192187823
}

The ConversationMessage object

ConversationMessage objects represent the specific interactions that have taken place in the Conversation:

  • id: A unique identifier for the conversation message.
  • conversation_id: A unique identifier of the parent conversation.
  • user_id: A unique identifier for the subscriber.
  • ts: The timestamp, in Unix Epoch, when the message was created.
  • details: Additional metadata associated with the conversation.
  • type: The type of the conversation message.
  • subtype: The subtype of the conversation message.
  • kind: The kind of the conversation message.

Here is an example of a ConversationMessage object:

{
"id": "3c114417-5cc0-4d03-a30f-c90659028d73",
"conversation_id": "9dbe9e94-c797-461e-b5a3-af6d095deaf4",
"user_id": "cecbe021-ff86-4ac6-bdf3-399ca477ad6f",
"ts": 1708192187.6779745,
"details": {},
"type": "message",
"subtype": "log",
"kind": "call_started"
}

Methods

getConversations

getConversations(): Promise<{ data: Conversation[], hasNext, hasPrev }> -

Returns a list of Conversation objects.

Returns

Promise<{ data: Conversation[], hasNext, hasPrev }>

Example

await client.conversation.getConversations();
{
"data": [
{
"id": "9dbe9e94-c797-461e-b5a3-af6d095deaf4",
"name": "conversation-office",
"metadata": {},
"created_at": 1708192187729,
"last_message_at": 1708192187823
}
],
"hasNext": false,
"hasPrev": false
}

getConversationMessages

getConversationMessages(options): Promise<{ data: ConversationMessage[], hasNext, hasPrev }>

Returns a list of ConversationMessage objects inside a Conversation with an Address ID.

Parameters

NameTypeDefault valueDescription
optionsobject-
options.addressIdstringundefinedGet Conversation Messages for between the Subscriber and this Address ID.
options.limit?numberundefinedThe maximum number of messages to retrieve.
options.since?numberundefinedThe Unix timestamp in seconds to retrieve messages since.
options.until?numberundefinedThe Unix timestamp in seconds to retrieve messages until.

Returns

Promise<{ data: ConversationMessage[], hasNext, hasPrev }>

Example

await client.conversation.getConversationMessages({
addressId: "9dbe9e94-c797-461e-b5a3-af6d095deaf4",
});
{
"data": [
{
"id": "3c114417-5cc0-4d03-a30f-c90659028d73",
"conversation_id": "9dbe9e94-c797-461e-b5a3-af6d095deaf4",
"user_id": "cecbe021-ff86-4ac6-bdf3-399ca477ad6f",
"ts": 1708192187.6779745,
"details": {},
"type": "message",
"subtype": "log",
"kind": "call_started"
}
],
"hasNext": false,
"hasPrev": false
}

getMessages

getMessages(options): Promise<{ data: ConversationMessage[], hasNext, hasPrev }>

Returns a list of ConversationMessage objects without filtering by Address ID.

Parameters

NameTypeDefault valueDescription
optionsobject-
options.limit?numberundefinedThe maximum number of messages to retrieve.
options.since?numberundefinedThe Unix timestamp in seconds to retrieve messages since.
options.until?numberundefinedThe Unix timestamp in seconds to retrieve messages until.

Returns

Promise<{ data: ConversationMessage[], hasNext, hasPrev }>

Example

await client.conversation.getMessages();
{
"data": [
{
"id": "3c114417-5cc0-4d03-a30f-c90659028d73",
"conversation_id": "9dbe9e94-c797-461e-b5a3-af6d095deaf4",
"user_id": "cecbe021-ff86-4ac6-bdf3-399ca477ad6f",
"ts": 1708192187.6779745,
"details": {},
"type": "message",
"subtype": "log",
"kind": "call_started"
}
],
"hasNext": false,
"hasPrev": false
}

subscribe

subscribe(): Promise<void>

Subscribe to receive new ConversationMessage objects as they happen.

Returns

Promise<void>

Example

client.conversation.subscribe((conversationMessage) => {
console.log("New message received!", conversationMessage);
// Add conversationMessage to the UI
});
{
"id": "916ea1c0-3381-42a3-8ca1-1095f13b4af0",
"type": "message",
"subtype": "log",
"kind": "call_started",
"hidden": "false",
"address_id": "9dbe9e94-c797-461e-b5a3-af6d095deaf4",
"conversation_id": "9dbe9e94-c797-461e-b5a3-af6d095deaf4",
"user_id": "cecbe021-ff86-4ac6-bdf3-399ca477ad6f",
"ts": 1708621363.211084,
"metadata": {},
"details": {},
"text": null,
"conversation_name": "conversation-office",
"user_name": "Jim Carrey"
}

sendMessage

sendMessage(options): Promise<Conversation>

Sends a Chat Message to the Conversation. This is the same function as chat.sendMessage.

Parameters

NameTypeDescription
optionsobject
options.addressIdstringThe id of the address to send the message to.
options.textstringThe Message text content.
options.metadata?objectMetadata to go along with the Message.
options.details?objectExtra Message event details. Can be used to construct custom UIs, for example.

Example

await conversation.sendMessage({
text: "Hello from SignalWire!",
});

join

join(options): Promise<JoinConversationResponse>

Joins a conversation given an address, without having to send a message. Does nothing if you were already joined to the conversation. This is the same function as chat.join.

You automatically join a conversation when you send the first message to an address. The join method allows you to join a conversation without sending a message.

Parameters

NameTypeDescription
optionsobject
options.addressIdstringThe id of the address to join the conversation of.

Example

await conversation.join({
addressId: "9dbe9e94-c797-461e-b5a3-af6d095deaf4",
});